#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int m, n, expo;
float coef;
float C[1001];
int Csize;
int main()
{
    cin >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> expo >> coef;
        C[expo] += coef;
    }
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> expo >> coef;
        C[expo] += coef;
    }
    for (int i = 0; i < 1001; ++i)
    {
        if(C[i]!=0.0)
            Csize++;
    }
    cout << Csize;
    for (int i = 1000; i >= 0; --i)
    {
        if (C[i] != 0.0)
        {
            printf(" %d %.1f", i, C[i]);
        }
    }
    return 0;
}